<div class="grid">
<h3><?php echo $title?></h3>
<?php echo $find?>
<?php if($this->session->flashdata('vremove_success')===True){?>
<div class="success">
	<?php echo lang('REMOVE_SYSTEM_SUCCESS')?>
</div>
<?php }?>
<?php if($this->session->flashdata('vremove_failed')===True){?>
<div class="error">
	<?php echo lang('REMOVE_SYSTEM_ERROR')?>
</div>
<?php }?>
<?php echo  form_open(get_currcontroller()."/vremove/go", array('id'=>'vgrid_'.$orid, 'autocomplete'=>'off'))?>
<table cellpadding="0" cellspacing="0">
	<tr>
		<td colspan="<?php echo count($fields)+2?>" style="text-align: right;background-color: #f6f6f6;">
			<div class="column span-12" style="text-align: left;padding-top:3px;">
				<?php if(element('add_allow', $tools, null)) { ?>
					<input type="button" value="<?php echo lang('NEW_TOOL')?>" class="button" name="create_btn_<?php echo $orid?>" onclick="window.location='<?php echo site_url(get_currcontroller()."/vcreate/go");?>'">
				<?php  } ?>
				<?php if(element('delete_allow', $tools, null)) { ?>
					<input type="button" value="<?php echo lang('REMOVE_TOOL')?>" class="button" name="delete_btn_<?php echo $orid?>" id="delete_btn_<?php echo $orid?>">
				<?php  } ?>
			</div>
			<div class="column span-12 last">
				<div id="paging"><?php echo $paging?></div>
			</div>
		</td>
	</tr>
	<tr>
		<?php if(element('delete_allow', $tools, null)) { ?>
		<td class="gridHeader" style="padding-left: 2px; white-space: nowrap;">
				<input type="checkbox" name="all" id="call" value="1">
		</td>
		<?php  } ?> 
		<?php foreach($fields as $key=>$field) { ?>
		<td class="gridHeader" width="<?php echo element('colwidth', $field, '')?>" style="white-space: nowrap;">
			<?php  if($field['sort']) { ?>
			<?php echo anchor(get_currcontroller().'/vsort/'.$key, $field['label'], "title=\"".$field['label']."\"")?>
			&nbsp;&nbsp;&nbsp;
			<?php  if(element('c', $sort, null)==$key) { ?>
				<?php  if(element('r', $sort, null)=='ASC') { ?>
					<?php echo img('public/css/images/icons/arrow_down.gif')?>
				<?php  } else {?>
					<?php echo img('public/css/images/icons/arrow_up.gif')?>
				<?php  } ?>
			<?php  } else {?>
				<?php echo img('public/css/images/icons/arrow.gif')?>
			<?php  } ?>
			<?php  }else{ ?>
			<?php echo $field['label']?>
			<?php  } ?>
		</td>
		<?php }?>
		<td class="gridHeader">
			&nbsp;
		</td>
	</tr>
	<?php foreach($ds as $record) { ?>
	<tr class="dataRow" ondblclick="joinToParent('<?php echo $record->$jtp['val']?>', '<?php echo $record->$jtp['scr']?>')">
		<?php if(element('delete_allow', $tools, null)) { ?>
		<td>
				<input type="checkbox" name="row[]" value="<?php echo $record->rid?>" id="crow_<?php echo $record->rid?>">
		</td>
		<?php  } ?>
		<?php foreach($fields as $key=>$field) {?>
		<td style="<?php echo element('style', $field, '')?>">
			<?php echo get_valtype($record->$key, element('type', $field, ''))?> 
		</td>
		<?php }?>
		<td nowrap="nowrap" width="1%">
			
			<?php 
				foreach($tools as $key=>$val) {
					if(!$val) continue;
					# хак для заархивированных записей 
					if($record->archive && !element('archive_allow', $tools, null) && $key!='details_allow') {
						continue;
					} 
			?>
				<?php echo get_tool($key, $record->rid, 1)?>
			<?php }?>		
					
		</td>
	</tr>
	<?php }?>
	<tr>
		<td colspan="<?php echo count($fields)+2?>" style="text-align: right;background-color: #f6f6f6;">
			<div class="column span-12" style="text-align: left;padding-top:3px;">
				&nbsp;			
			</div>
			<div class="column span-12 last">
				<div id="paging"><?php echo $paging?><br></div>
			</div>
		</td>
	</tr>
</table>
<?php echo form_close();?>
</div>
<script type="text/javascript">
$(document).ready(function (){
	$('#call').click(function (){
       $("[name='row[]']").each( function() {
           $(this).attr('checked', !$(this).attr('checked'));
       });
	});
	$('#delete_btn_<?php echo $orid?>').click(function(){
		if(confirm('<?php echo lang('CONFIRM_DEL')?>')){
			$('#vgrid_<?php echo $orid?>').submit();
			return true;	
		} else {
			return false;
		}
	});	
})
function joinToParent(val, scr){
	$("input[name='<?php echo $jtp['val_p']?>']", window.opener.document).val(val);
	$('#<?php echo $jtp['scr_p']?>', window.opener.document).val(scr);
	this.close();
	return;
}	
</script>